/**
 * 
 */
package com.scpii.universal.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.dto.FavoritesDto;
import com.scpii.universal.hibernate.dao.ClientUserDao;
import com.scpii.universal.hibernate.entity.ClientUserTab;
import com.scpii.universal.service.ClientUserService;

/**
 * genericWeb
 * @author weny
 * 2012-7-8下午09:37:37
 */
@Service
public class ClientUserServiceImpl extends BaseServiceImpl<ClientUserTab, Integer> implements
		ClientUserService {
   @Resource
	private ClientUserDao clientUserDao;
   @Resource
	public void setBaseDao(ClientUserDao clientUserDao) {
		super.setBaseDao(clientUserDao);
	}
/* (non-Javadoc)
 * @see com.scpii.universal.service.ClientUserService#getClientUserRecode(com.scpii.universal.hibernate.entity.ClientUserTab)
 */
@Override
public Integer getClientUserRecode(ClientUserTab condition) {
	// TODO Auto-generated method stub
	StringBuffer hql = new StringBuffer("SELECT new com.scpii.universal.hibernate.entity.ClientUserTab(t1.intUserId )");
	hql.append(" from ClientUserTab t1  ");
	hql.append(" where t1.intDeleteSign=:intDeleteSign ");	
	hql.append(" and t1.intAppId=:intAppId ");	
	Map<String,Object> argsMap = new HashMap<String,Object>();	
	argsMap.put("intDeleteSign", GenericConstants.DELETE_SIGN_EXIST);
	//查询条件
	if(condition!=null){
		if(condition.getVarUserName()!=null&&!"".equals(condition.getVarUserName())){
			hql.append(" and t1.varUserName like:varUserName");
			argsMap.put("varUserName", "%"+condition.getVarUserName()+"%");
		}
	
		argsMap.put("intAppId", condition.getIntAppId());
	}
	 List<ClientUserTab> list= clientUserDao.hqlGetList(hql.toString(), argsMap);
		if(list!=null){
			return list.size();
		}else{
			return 0;
		}
}
/* (non-Javadoc)
 * @see com.scpii.universal.service.ClientUserService#getClientUserListPage(com.scpii.universal.hibernate.entity.ClientUserTab, int, int, int)
 */
@Override
public List<ClientUserTab> getClientUserListPage(ClientUserTab condition,
		int pageNo, int pageStart, int pageRecordNo) {
	// TODO Auto-generated method stub
	StringBuffer hql = new StringBuffer("SELECT  new com.scpii.universal.hibernate.entity.ClientUserTab(t1.intUserId, t1.intAppId,");
	hql.append("  t1.varUserName,t1.intUserSex,t1.datUserBirthday,");
	hql.append("  t1.varUserPhonenum,t1.varUserLoginName,");
	hql.append(" t1.varUserLoginPassword,t1.varUserWeiboAccount, ");
	hql.append("  t1.varNickName,t1.varDeviceId,t1.varImsi, ");
	hql.append(" t1.intOsType,t1.intDeleteSign,t1.datUpdateDatetime )");	
	hql.append(" from ClientUserTab t1  ");
	hql.append(" where t1.intDeleteSign=:intDeleteSign ");	
	hql.append(" and t1.intAppId=:intAppId ");	
	Map<String,Object> argsMap = new HashMap<String,Object>();	
	argsMap.put("intDeleteSign", GenericConstants.DELETE_SIGN_EXIST);
	//查询条件
	if(condition!=null){
		if(condition.getVarUserName()!=null&&!"".equals(condition.getVarUserName())){
			hql.append(" and t1.varUserName like:varUserName");
			argsMap.put("varUserName", "%"+condition.getVarUserName()+"%");
		}
	
		argsMap.put("intAppId", condition.getIntAppId());
	}
	
	return clientUserDao.findByHql(hql.toString(), pageNo, pageRecordNo, argsMap);
}

}
